package com.zhiqianbao.utils;

import android.app.Activity;
import android.graphics.Color;
import android.view.View;

import com.bigkoo.pickerview.OptionsPickerView;
import com.zhiqianbao.entity.WorkIndustryInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by liudehong on 2017/9/21.
 * 弹出框展示子女，工作信息，银行等分类信息
 */
public class DialogWorkIndustryTypeUtils {
    private List<String> workFirstMsgs=new ArrayList<>();
    private List<List<String>> workSecondsMsgs=new ArrayList<>();
    public DialogWorkIndustryTypeUtils(Activity activity,ArrayList<WorkIndustryInfo> options1Items,
        ArrayList<ArrayList<WorkIndustryInfo>> options2Items,WorkIndustryCallBack callBack){
        showPickerView(activity,options1Items,options2Items,callBack);
    }

    public void showPickerView(Activity activity,final ArrayList<WorkIndustryInfo> options1Items,
                               final ArrayList<ArrayList<WorkIndustryInfo>> options2Items,
                               final WorkIndustryCallBack callBack) {
        if(activity==null){
            return;
        }
        setData(options1Items,options2Items);
        OptionsPickerView pvOptions = new OptionsPickerView.Builder(activity, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                //返回的分别是三个级别的选中位置
                int firstCode=options1Items.get(options1).getCode();
                int secondCode=options2Items.get(options1).get(options2).getCode();
                callBack.workInfoCallBack(firstCode,secondCode);
                }
              }).setTitleText("")
                .setDividerColor(Color.GRAY)
                .setTextColorCenter(Color.GRAY)
                .setContentTextSize(14)
                .setLineSpacingMultiplier(2.0f)
                .setOutSideCancelable(false)
                .build();
          /*pvOptions.setPicker(options1Items);//一级选择器*/
        pvOptions.setPicker(workFirstMsgs, workSecondsMsgs);//二级选择器
        pvOptions.show();

    }

    public void setData(final ArrayList<WorkIndustryInfo> options1Items,
                        final ArrayList<ArrayList<WorkIndustryInfo>> options2Items) {

        int firstSizes = options1Items.size();
        int secondSizes = options2Items.size();
        for (int i = 0; i < firstSizes; i++) {
            workFirstMsgs.add(options1Items.get(i).getWorkIndustry());
            List<String> items = new ArrayList<>();
            for(int j=0;j<options2Items.get(i).size();j++){
                String item=options2Items.get(i).get(j).getWorkIndustry();
                items.add(item);
            }
            workSecondsMsgs.add(items);
        }
    }

    public interface  WorkIndustryCallBack{
        void workInfoCallBack(int firstCode,int secondCode);
    }
}
